﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using Assist;
using Autodesk.Revit.DB;
using YArchitech.LIB;

namespace YJKInspectModel.ModelValidation.ClearHeightCheck
{
	public partial class FillPatternForm : System.Windows.Forms.Form
	{
		public FillPatternForm(Autodesk.Revit.DB.Document m_Doc, FillFatternType type)
		{
			this.InitializeComponent();
			this.doc = m_Doc;
			this.type = type;
		}

		private void FillPatternForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			if (this.type == FillFatternType.Color)
			{
				base.Width = 561;
				this.dgvFillPattern.Width = 464;
				this.tabControl1.Width = 525;
				this.btnOK.Location = new System.Drawing.Point(379, 426);
				this.btnCancel.Location = new System.Drawing.Point(459, 426);
				this.Text = "颜色填充方案";
				this.dgvFillPattern.Columns[5].Visible = false;
			}
			this.collection = this.GetFillPatternElementCollection();
			this.m_FillPattenList = this.GetPatternList();
			foreach (FillPattern fillPattern in this.m_FillPattenList)
			{
				if (fillPattern.IsSolidFill)
				{
					this.solidFill = fillPattern;
					break;
				}
			}
			DataGridViewComboBoxColumn dataGridViewComboBoxColumn = this.dgvFillPattern.Columns[5] as DataGridViewComboBoxColumn;
			foreach (FillPattern fillPattern2 in this.m_FillPattenList)
			{
				dataGridViewComboBoxColumn.Items.Add(fillPattern2.Name);
			}
			List<FillPatternStruc> fillPatternStrucs = this.ReadData();
			this.FilldgvFillPattern(fillPatternStrucs);
		}

		private void dgvFillPattrn_CellClick(object sender, DataGridViewCellEventArgs e)
		{
			if (e.RowIndex >= 0 && e.ColumnIndex == 4)
			{
				System.Drawing.Color black = System.Drawing.Color.Black;
				System.Drawing.Color colorByString = this.GetColorByString(this.dgvFillPattern.CurrentCell.Value.ToString());
				if (this.ShowColorDialog(colorByString, ref black))
				{
					string text = black.R.ToString();
					string text2 = black.G.ToString();
					string text3 = black.B.ToString();
					this.dgvFillPattern[4, e.RowIndex].Value = string.Concat(new string[]
					{
						"█RGB ",
						text,
						" ",
						text2,
						" ",
						text3
					});
					this.dgvFillPattern[4, e.RowIndex].Style.ForeColor = black;
					this.dgvFillPattern[4, e.RowIndex].ReadOnly = true;
					string style = this.dgvFillPattern.Rows[this.dgvFillPattern.CurrentRow.Index].Cells[this.dgvFillPattern.CurrentCell.ColumnIndex + 1].Value.ToString();
					List<FillPattern> list = (from f in this.m_FillPattenList
					where f.Name == style
					select f).ToList<FillPattern>();
					this.dgvFillPattern.Rows[this.dgvFillPattern.CurrentRow.Index].Cells[this.dgvFillPattern.CurrentCell.ColumnIndex + 2].Value = this.GetPatternImage(list[0], black);
					return;
				}
			}
			else if (e.RowIndex == 0 || e.RowIndex == 1)
			{
				if (this.btnReduction.Enabled)
				{
					this.btnReduction.Enabled = false;
					return;
				}
			}
			else if (e.RowIndex > 1 && !this.btnReduction.Enabled)
			{
				this.btnReduction.Enabled = true;
			}
		}

		private void dgvFillPattrn_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
		{
			if (this.dgvFillPattern.CurrentCell.OwningColumn.Name == "Fillstyle")
			{
				((System.Windows.Forms.ComboBox)e.Control).SelectedIndexChanged -= this.ComboBox_SelectedIndexChanged;
				((System.Windows.Forms.ComboBox)e.Control).SelectedIndexChanged += this.ComboBox_SelectedIndexChanged;
				return;
			}
			if (this.dgvFillPattern.CurrentCell.OwningColumn.Name == "start")
			{
				e.Control.KeyPress -= this.TextBoxDec_KeyPress;
				e.Control.KeyPress += this.TextBoxDec_KeyPress;
				return;
			}
			e.Control.KeyPress -= this.TextBoxDec_KeyPress;
		}

		private void dgvFillPattern_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
		{
			if (this.dgvFillPattern.Columns[e.ColumnIndex].Name == "start" && this.dgvFillPattern.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
			{
				this.editStart = this.dgvFillPattern.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
			}
		}

		private void dgvFillPattern_CellEndEdit(object sender, DataGridViewCellEventArgs e)
		{
			if (this.dgvFillPattern.Columns[e.ColumnIndex].Name == "start")
			{
				double num = Convert.ToDouble(this.dgvFillPattern.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
				if (e.RowIndex == 1)
				{
					if (this.dgvFillPattern.Rows.Count != 2)
					{
						double num2 = Convert.ToDouble(this.dgvFillPattern.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value);
						if (num >= num2)
						{
							MessageBox.Show("数值必须小于" + num2 + "。", "盈建科提示");
							this.editRowIndex = e.RowIndex;
							this.editColIndex = e.ColumnIndex;
							this.dgvFillPattern.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = this.editStart;
							return;
						}
					}
				}
				else if (e.RowIndex == this.dgvFillPattern.Rows.Count - 1)
				{
					double num3 = Convert.ToDouble(this.dgvFillPattern.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value);
					if (num <= num3)
					{
						MessageBox.Show("数值必须大于" + num3 + "。", "盈建科提示");
						this.editRowIndex = e.RowIndex;
						this.editColIndex = e.ColumnIndex;
						this.dgvFillPattern.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = this.editStart;
						return;
					}
				}
				else
				{
					double num3 = Convert.ToDouble(this.dgvFillPattern.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value);
					double num2 = Convert.ToDouble(this.dgvFillPattern.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value);
					if (num <= num3)
					{
						MessageBox.Show("数值必须大于" + num3 + "。", "盈建科提示");
						this.editRowIndex = e.RowIndex;
						this.editColIndex = e.ColumnIndex;
						this.dgvFillPattern.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = this.editStart;
						return;
					}
					if (num >= num2)
					{
						MessageBox.Show("数值必须小于" + num2 + "。", "盈建科提示");
						this.editRowIndex = e.RowIndex;
						this.editColIndex = e.ColumnIndex;
						this.dgvFillPattern.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = this.editStart;
						return;
					}
				}
				this.dgvFillPattern.Rows[e.RowIndex - 1].Cells[e.ColumnIndex + 1].Value = num;
			}
		}

		private void dgvFillPattern_SelectionChanged(object sender, EventArgs e)
		{
			if (this.editRowIndex != -1 && this.editColIndex != -1)
			{
				int index = this.editRowIndex;
				int index2 = this.editColIndex;
				this.editRowIndex = -1;
				this.editColIndex = -1;
				this.dgvFillPattern.Rows[index].Cells[index2].Selected = true;
			}
		}

		private void dgvFillPattrn_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
		{
			if (e.ColumnIndex == 4)
			{
				e.CellStyle.SelectionForeColor = e.CellStyle.ForeColor;
			}
		}

		private void dgvFillPattrn_DataError(object sender, DataGridViewDataErrorEventArgs e)
		{
		}

		private void btnPlus_Click(object sender, EventArgs e)
		{
			double num = Convert.ToDouble(this.txtIncrease.Text.Trim());
			int rowIndex = this.dgvFillPattern.SelectedCells[0].RowIndex;
			if (rowIndex == 0)
			{
				double num2 = Convert.ToDouble(this.dgvFillPattern.Rows[rowIndex + 1].Cells[0].Value);
				this.dgvFillPattern.Rows[rowIndex].Cells[1].Value = num2 - num;
				this.dgvFillPattern.Rows.Insert(rowIndex + 1, new DataGridViewRow());
				this.dgvFillPattern.Rows[rowIndex + 1].Cells[0].Value = num2 - num;
				this.dgvFillPattern.Rows[rowIndex + 1].Cells[1].Value = num2;
				this.dgvFillPattern.Rows[rowIndex + 1].Cells[2].Value = num2 - num + "-" + num2;
			}
			else if (rowIndex == this.dgvFillPattern.Rows.Count - 1)
			{
				double num3 = Convert.ToDouble(this.dgvFillPattern.Rows[rowIndex].Cells[0].Value);
				this.dgvFillPattern.Rows[rowIndex].Cells[1].Value = num3 + num;
				this.dgvFillPattern.Rows[rowIndex].Cells[2].Value = num3 + "-" + (num3 + num);
				this.dgvFillPattern.Rows.Insert(rowIndex + 1, new DataGridViewRow());
				this.dgvFillPattern.Rows[rowIndex + 1].Cells[0].Value = num3 + num;
				this.dgvFillPattern.Rows[rowIndex + 1].Cells[1].Value = "";
				this.dgvFillPattern.Rows[rowIndex + 1].Cells[2].Value = num3 + num + "或更多";
			}
			else
			{
				double num3 = Convert.ToDouble(this.dgvFillPattern.Rows[rowIndex].Cells[0].Value);
				double num4 = Convert.ToDouble(this.dgvFillPattern.Rows[rowIndex + 1].Cells[0].Value);
				if (num3 + num >= num4)
				{
					MessageBox.Show("无法拆分范围。", "盈建科提示");
					return;
				}
				this.dgvFillPattern.Rows[rowIndex].Cells[1].Value = num3 + num;
				this.dgvFillPattern.Rows.Insert(rowIndex + 1, new DataGridViewRow());
				this.dgvFillPattern.Rows[rowIndex + 1].Cells[0].Value = num3 + num;
				this.dgvFillPattern.Rows[rowIndex + 1].Cells[1].Value = num4;
				this.dgvFillPattern.Rows[rowIndex + 1].Cells[2].Value = num3 + num + "-" + num4;
			}
			this.dgvFillPattern.Rows[rowIndex + 1].Cells[3].Value = true;
			System.Drawing.Color randomColor = this.GetRandomColor();
			this.dgvFillPattern.Rows[rowIndex + 1].Cells[4].Value = string.Concat(new object[]
			{
				"█RGB ",
				randomColor.R,
				" ",
				randomColor.G,
				" ",
				randomColor.B
			});
			this.dgvFillPattern.Rows[rowIndex + 1].Cells[4].Style.ForeColor = randomColor;
			if (this.type == FillFatternType.Color)
			{
				this.dgvFillPattern.Rows[rowIndex + 1].Cells[5].Value = this.solidFill.Name;
				this.dgvFillPattern.Rows[rowIndex + 1].Cells[6].Value = this.GetPatternImage(this.solidFill, randomColor);
			}
			else
			{
				this.dgvFillPattern.Rows[rowIndex + 1].Cells[5].Value = this.solidFill.Name;
				this.dgvFillPattern.Rows[rowIndex + 1].Cells[6].Value = this.GetPatternImage(this.solidFill, randomColor);
			}
			if (this.dgvFillPattern.Rows.Count == 2)
			{
				this.btnReduction.Enabled = false;
			}
			if (this.dgvFillPattern.SelectedCells[0].RowIndex == 0 || this.dgvFillPattern.SelectedCells[0].RowIndex == 1)
			{
				this.btnReduction.Enabled = false;
			}
		}

		private void btnReduction_Click(object sender, EventArgs e)
		{
			int rowIndex = this.dgvFillPattern.SelectedCells[0].RowIndex;
			if (rowIndex == 0 || rowIndex == 1)
			{
				return;
			}
			this.dgvFillPattern.Rows.RemoveAt(rowIndex);
			if (this.dgvFillPattern.Rows.Count == 2)
			{
				this.btnReduction.Enabled = false;
			}
			if (this.dgvFillPattern.SelectedCells[0].RowIndex == 0 || this.dgvFillPattern.SelectedCells[0].RowIndex == 1)
			{
				this.btnReduction.Enabled = false;
			}
		}

		private void btnClear_Click(object sender, EventArgs e)
		{
			if (MessageBox.Show("是否确定将现有方案清空,清空后将无法恢复。", "盈建科提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
			{
				this.dgvFillPattern.Rows.Clear();
				List<FillPatternStruc> list = new List<FillPatternStruc>();
				XmlDocument xmlDocument = new XmlDocument();
				xmlDocument.Load(this.backupxmlFilePath);
				XmlNodeList xmlNodeList;
				if (this.type == FillFatternType.Color)
				{
					xmlNodeList = xmlDocument.SelectNodes("FillPatterns/ColorLeastDefaultValue/FillPattern");
				}
				else
				{
					xmlNodeList = xmlDocument.SelectNodes("FillPatterns/LeastDefaultValue/FillPattern");
				}
				for (int i = 0; i < xmlNodeList.Count; i++)
				{
					FillPatternStruc fillPatternStruc = new FillPatternStruc();
					if (i == 0)
					{
						fillPatternStruc.Start = -1.0;
						fillPatternStruc.Lessthan = Convert.ToDouble(xmlNodeList[i].Attributes[1].Value);
					}
					else if (i == xmlNodeList.Count - 1)
					{
						fillPatternStruc.Start = Convert.ToDouble(xmlNodeList[i].Attributes[0].Value);
						fillPatternStruc.Lessthan = -1.0;
					}
					fillPatternStruc.Title = xmlNodeList[i].Attributes[2].Value;
					fillPatternStruc.Visible = Convert.ToBoolean(xmlNodeList[i].Attributes[3].Value);
					string[] array = xmlNodeList[i].Attributes[4].Value.Split(new char[]
					{
						' '
					});
					fillPatternStruc.Color = System.Drawing.Color.FromArgb(Convert.ToInt32(array[0]), Convert.ToInt32(array[1]), Convert.ToInt32(array[2]));
					if (this.type == FillFatternType.Color)
					{
						fillPatternStruc.Fillstyle = this.solidFill.Name;
					}
					else
					{
						ElementId id = new ElementId(Convert.ToInt32(xmlNodeList[i].Attributes[5].Value));
						fillPatternStruc.Fillstyle = this.GetPatternById(id).Name;
					}
					list.Add(fillPatternStruc);
				}
				this.FilldgvFillPattern(list);
				this.btnReduction.Enabled = false;
			}
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			this.SaveData();
		}

		private void TextBoxDec_KeyPress(object sender, KeyPressEventArgs e)
		{
			System.Windows.Forms.TextBox textBox = sender as System.Windows.Forms.TextBox;
			this.Validata(textBox.Text.Trim(), e);
		}

		private void Validata(string txt, KeyPressEventArgs e)
		{
			if (e.KeyChar == ' ')
			{
				e.Handled = true;
				return;
			}
			if (e.KeyChar == '\b')
			{
				return;
			}
			double num = 0.0;
			if (!double.TryParse(txt + e.KeyChar.ToString(), out num))
			{
				e.Handled = true;
				return;
			}
			if (num >= 0.0)
			{
				e.Handled = false;
				return;
			}
			e.Handled = true;
		}

		private void FilldgvFillPattern(List<FillPatternStruc> m_FillPatternStrucs)
		{
			for (int i = 0; i < m_FillPatternStrucs.Count; i++)
			{
				int index = this.dgvFillPattern.Rows.Add();
				if (i == 0)
				{
					this.dgvFillPattern.Rows[index].Cells[0].Value = "";
					this.dgvFillPattern.Rows[index].Cells[1].Value = m_FillPatternStrucs[i].Lessthan;
				}
				else if (i == m_FillPatternStrucs.Count - 1)
				{
					this.dgvFillPattern.Rows[index].Cells[0].Value = m_FillPatternStrucs[i].Start;
					this.dgvFillPattern.Rows[index].Cells[1].Value = "";
				}
				else
				{
					this.dgvFillPattern.Rows[index].Cells[0].Value = m_FillPatternStrucs[i].Start;
					this.dgvFillPattern.Rows[index].Cells[1].Value = m_FillPatternStrucs[i].Lessthan;
				}
				this.dgvFillPattern.Rows[index].Cells[2].Value = m_FillPatternStrucs[i].Title;
				this.dgvFillPattern.Rows[index].Cells[3].Value = m_FillPatternStrucs[i].Visible;
				this.dgvFillPattern.Rows[index].Cells[4].Value = string.Concat(new object[]
				{
					"█RGB ",
					m_FillPatternStrucs[i].Color.R,
					" ",
					m_FillPatternStrucs[i].Color.G,
					" ",
					m_FillPatternStrucs[i].Color.B
				});
				this.dgvFillPattern.Rows[index].Cells[4].Style.ForeColor = m_FillPatternStrucs[i].Color;
				this.dgvFillPattern.Rows[index].Cells[5].Value = m_FillPatternStrucs[i].Fillstyle;
				this.dgvFillPattern.Rows[index].Cells[6].Value = this.GetPatternImage(this.GetPatternById(this.GetPatternIdByName(m_FillPatternStrucs[i].Fillstyle)), m_FillPatternStrucs[i].Color);
			}
			this.dgvFillPattern.Rows[0].Cells[0].ReadOnly = true;
			this.btnReduction.Enabled = false;
		}

		public System.Drawing.Color GetColorByString(string rgb)
		{
			string[] array = rgb.Split(new char[]
			{
				' '
			});
			return System.Drawing.Color.FromArgb(Convert.ToInt32(array[1]), Convert.ToInt32(array[2]), Convert.ToInt32(array[3]));
		}

		private bool ShowColorDialog(System.Drawing.Color oldColor, ref System.Drawing.Color newColor)
		{
			ColorDialog colorDialog = new ColorDialog();
			colorDialog.AllowFullOpen = true;
			colorDialog.FullOpen = true;
			colorDialog.ShowHelp = true;
			colorDialog.Color = oldColor;
			if (colorDialog.ShowDialog() != DialogResult.OK)
			{
				return false;
			}
			newColor = colorDialog.Color;
			return true;
		}

		private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
		{
			System.Windows.Forms.ComboBox cmb = sender as System.Windows.Forms.ComboBox;
			List<FillPattern> list = (from f in this.m_FillPattenList
			where f.Name == cmb.SelectedItem.ToString()
			select f).ToList<FillPattern>();
			System.Drawing.Color colorByString = this.GetColorByString(this.dgvFillPattern.Rows[this.dgvFillPattern.CurrentRow.Index].Cells[this.dgvFillPattern.CurrentCell.ColumnIndex - 1].Value.ToString());
			this.dgvFillPattern.Rows[this.dgvFillPattern.CurrentRow.Index].Cells[this.dgvFillPattern.CurrentCell.ColumnIndex + 1].Value = this.GetPatternImage(list[0], colorByString);
		}

		private List<FillPattern> GetPatternList()
		{
			List<FillPattern> list = new List<FillPattern>();
			foreach (Element element in this.collection)
			{
				FillPattern fillPattern = (element as FillPatternElement).GetFillPattern();
				list.Add(fillPattern);
			}
			list.Sort(new FillPatternComparer());
			return list;
		}

		private Image GetPatternImage(FillPattern fillPattern, System.Drawing.Color color)
		{
			return FillPatternDrawingKit.CreateFillPatternImage(fillPattern, (double)this.Preview.Width, (double)(this.dgvFillPattern.RowTemplate.Height + 6), color);
		}

		public System.Drawing.Color GetRandomColor()
		{
			Random random = new Random((int)DateTime.Now.Ticks);
			Thread.Sleep(random.Next(50));
			Random random2 = new Random((int)DateTime.Now.Ticks);
			int num = random.Next(256);
			int num2 = random2.Next(256);
			int num3 = (num + num2 > 400) ? 0 : (400 - num - num2);
			num3 = ((num3 > 255) ? 255 : num3);
			return System.Drawing.Color.FromArgb(num, num2, num3);
		}

		private void txtIncrease_KeyPress(object sender, KeyPressEventArgs e)
		{
			this.Validata(this.txtIncrease.Text.Trim(), e);
		}

		private void txtIncrease_TextChanged(object sender, EventArgs e)
		{
			if (this.txtIncrease.Text.Length < 1)
			{
				MessageBox.Show("递增值不能为空。", "盈建科提示");
				this.txtIncrease.Text = "0.300";
				this.txtIncrease.SelectAll();
			}
		}

		private FillPattern GetPatternById(ElementId id)
		{
			FillPatternElement fillPatternElement = null;
			foreach (Element element in this.collection)
			{
				FillPatternElement fillPatternElement2 = element as FillPatternElement;
				if (fillPatternElement2.Id.IntegerValue == id.IntegerValue)
				{
					fillPatternElement = fillPatternElement2;
					break;
				}
			}
			if (fillPatternElement == null)
			{
				fillPatternElement = (this.collection.First<Element>() as FillPatternElement);
			}
			return fillPatternElement.GetFillPattern();
		}

		private ElementId GetPatternIdByName(string name)
		{
			FillPatternElement fillPatternElement = null;
			foreach (Element element in this.collection)
			{
				FillPatternElement fillPatternElement2 = element as FillPatternElement;
				if (fillPatternElement2.Name == name)
				{
					fillPatternElement = fillPatternElement2;
					break;
				}
			}
			if (fillPatternElement == null)
			{
				fillPatternElement = (this.collection.First<Element>() as FillPatternElement);
			}
			return fillPatternElement.Id;
		}

		private ICollection<Element> GetFillPatternElementCollection()
		{
			return new FilteredElementCollector(this.doc).OfClass(typeof(FillPatternElement)).ToElements();
		}

		private List<FillPatternStruc> ReadData()
		{
			List<FillPatternStruc> list = new List<FillPatternStruc>();
			string text = Path.GetTempPath() + "FillPatternConfig.xml";
			if (!File.Exists(text))
			{
				File.AppendAllText(text, File.ReadAllText(this.backupxmlFilePath));
			}
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(text);
			XmlNodeList xmlNodeList;
			if (this.type == FillFatternType.Color)
			{
				xmlNodeList = xmlDocument.SelectNodes("FillPatterns/ColorDefaultValue/FillPattern");
			}
			else
			{
				xmlNodeList = xmlDocument.SelectNodes("FillPatterns/DefaultValue/FillPattern");
			}
			for (int i = 0; i < xmlNodeList.Count; i++)
			{
				FillPatternStruc fillPatternStruc = new FillPatternStruc();
				if (i == 0)
				{
					fillPatternStruc.Start = -1.0;
					fillPatternStruc.Lessthan = Convert.ToDouble(xmlNodeList[i].Attributes[1].Value);
				}
				else if (i == xmlNodeList.Count - 1)
				{
					fillPatternStruc.Start = Convert.ToDouble(xmlNodeList[i].Attributes[0].Value);
					fillPatternStruc.Lessthan = -1.0;
				}
				else
				{
					fillPatternStruc.Start = Convert.ToDouble(xmlNodeList[i].Attributes[0].Value);
					fillPatternStruc.Lessthan = Convert.ToDouble(xmlNodeList[i].Attributes[1].Value);
				}
				fillPatternStruc.Title = xmlNodeList[i].Attributes[2].Value;
				fillPatternStruc.Visible = Convert.ToBoolean(xmlNodeList[i].Attributes[3].Value);
				string[] array = xmlNodeList[i].Attributes[4].Value.Split(new char[]
				{
					' '
				});
				fillPatternStruc.Color = System.Drawing.Color.FromArgb(Convert.ToInt32(array[0]), Convert.ToInt32(array[1]), Convert.ToInt32(array[2]));
				if (this.type == FillFatternType.Color)
				{
					fillPatternStruc.Fillstyle = this.solidFill.Name;
				}
				else
				{
					ElementId id = new ElementId(Convert.ToInt32(xmlNodeList[i].Attributes[5].Value));
					fillPatternStruc.Fillstyle = this.GetPatternById(id).Name;
				}
				list.Add(fillPatternStruc);
			}
			return list;
		}

		private void SaveData()
		{
			string text = Path.GetTempPath() + "FillPatternConfig.xml";
			XmlDocument xmlDocument = new XmlDocument();
			if (!File.Exists(text))
			{
				File.AppendAllText(text, File.ReadAllText(this.backupxmlFilePath));
			}
			xmlDocument.Load(text);
			XmlNode xmlNode;
			if (this.type == FillFatternType.Color)
			{
				xmlNode = xmlDocument.SelectSingleNode("FillPatterns/ColorDefaultValue");
			}
			else
			{
				xmlNode = xmlDocument.SelectSingleNode("FillPatterns/DefaultValue");
			}
			((XmlElement)xmlNode).RemoveAll();
			for (int i = 0; i < this.dgvFillPattern.Rows.Count; i++)
			{
				XmlElement xmlElement = xmlDocument.CreateElement("FillPattern");
				if (i == 0)
				{
					xmlElement.SetAttribute("Start", "");
					xmlElement.SetAttribute("Lessthan", this.dgvFillPattern.Rows[i].Cells[1].Value.ToString());
				}
				else if (i == this.dgvFillPattern.Rows.Count - 1)
				{
					xmlElement.SetAttribute("Start", this.dgvFillPattern.Rows[i].Cells[0].Value.ToString());
					xmlElement.SetAttribute("Lessthan", "");
				}
				else
				{
					xmlElement.SetAttribute("Start", this.dgvFillPattern.Rows[i].Cells[0].Value.ToString());
					xmlElement.SetAttribute("Lessthan", this.dgvFillPattern.Rows[i].Cells[1].Value.ToString());
				}
				xmlElement.SetAttribute("Title", this.dgvFillPattern.Rows[i].Cells[2].Value.ToString());
				xmlElement.SetAttribute("Visible", this.dgvFillPattern.Rows[i].Cells[3].Value.ToString());
				System.Drawing.Color colorByString = this.GetColorByString(this.dgvFillPattern.Rows[i].Cells[4].Value.ToString());
				xmlElement.SetAttribute("Color", string.Concat(new object[]
				{
					colorByString.R,
					" ",
					colorByString.G,
					" ",
					colorByString.B
				}));
				if (this.type == FillFatternType.Pattern)
				{
					xmlElement.SetAttribute("Fillstyle", this.GetPatternIdByName(this.dgvFillPattern.Rows[i].Cells[5].Value.ToString()).ToString());
				}
				xmlNode.AppendChild(xmlElement);
			}
			xmlDocument.Save(text);
		}

		private Document doc;

		private string backupxmlFilePath = AssistFunc.GetAppRootPath() + "\\Data\\FillPatternConfig.xml";

		private ICollection<Element> collection;

		private List<FillPattern> m_FillPattenList = new List<FillPattern>();

		private FillPattern solidFill;

		private object editStart;

		private int editRowIndex = -1;

		private int editColIndex = -1;

		private FillFatternType type;
	}
}
